<?php
allowCors();
if (!methodsRequired(['post'])) return;
if (!checkAdmin($msg)) return;

if (isset($_REQUEST['gp_name']) && isset($_REQUEST['dept_id'])) {
    $group = new Group();
    $group->setGpName($_REQUEST['gp_name']);
    $group->setDeptId($_REQUEST['dept_id']);
    if (isset($_REQUEST['grouper_id']))
        $group->setGrouperId($_REQUEST['grouper_id']);
    if ($db->add($group)) {
        $msg->setCode(0);
    } else {
        $msg->setCode(1);
    }
} else {
    $msg->setCode(1);
}
echo $msg;